package com.shiro.demo.domain;

import org.apache.ibatis.session.RowBounds;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import java.io.Serializable;

public class Pager<T> extends RowBounds implements Pageable, Serializable {
    private long total;
    private T data;
    private int pageNo = 1; //vision的page是从1开始的
    private int pageSize = 10;

    Pager() {
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public Pager(int pageNo, int pageSize) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
    }

    public void setData(T data) {
        this.data = data;
    }

    public T getData() {
        return this.data;
    }

    public long getTotal() {
        return this.total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPage() {
        return this.pageNo;
    }

    public void setPage(int page) {
        this.pageNo = pageNo;
    }

    public int getSize() {
        return this.pageSize;
    }

    public void setSize(int size) {
        this.pageSize = pageSize;
    }

    public int getPageNumber() {
        return (this.pageNo - 1) * this.pageSize;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public int getOffset() {
        return 0;
    }

    public Sort getSort() {
        return null;
    }

    public Pageable next() {
        return new Pager(this.pageNo + 1, this.pageSize);
    }

    public Pageable previousOrFirst() {
        return null;
    }

    public Pageable first() {
        return null;
    }

    public boolean hasPrevious() {
        return false;
    }

    @Override
    public String toString() {
        return "Pager{" +
                "total=" + total +
                ", data=" + data +
                ", pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                '}';
    }
}
